package team2.game.crow;

import org.anddev.andengine.engine.Engine;
import org.anddev.andengine.engine.camera.Camera;
import org.anddev.andengine.engine.options.EngineOptions;
import org.anddev.andengine.engine.options.EngineOptions.ScreenOrientation;
import org.anddev.andengine.engine.options.resolutionpolicy.RatioResolutionPolicy;
import org.anddev.andengine.entity.scene.Scene;
import org.anddev.andengine.entity.scene.Scene.IOnSceneTouchListener;
import org.anddev.andengine.entity.sprite.Sprite;
import org.anddev.andengine.entity.text.Text;
import org.anddev.andengine.input.touch.TouchEvent;
import org.anddev.andengine.opengl.font.Font;
import org.anddev.andengine.opengl.font.FontFactory;
import org.anddev.andengine.opengl.texture.Texture;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlas;
import org.anddev.andengine.opengl.texture.atlas.bitmap.BitmapTextureAtlasTextureRegionFactory;
import org.anddev.andengine.opengl.texture.region.TextureRegion;
import org.anddev.andengine.ui.activity.BaseGameActivity;

import android.content.Intent;
import android.graphics.Color;

public class MainMenu extends BaseGameActivity implements IOnSceneTouchListener{

	
	// ===========================================================
	// Constants
	// ===========================================================
	
	private static final int CAMERA_WIDTH = 480;
    private static final int CAMERA_HEIGHT = 720;

	// ===========================================================
	// Fields
	// ===========================================================
	
	private Scene scene;
	private Camera camera;
	private Font font;
	private TextureRegion newGame;
	private Text loadGame;
	//private Text levelSelect;
	private BitmapTextureAtlas spriteBox;
	private Texture fontBox;
	private TextureRegion backgroundTexture;
	private Sprite background;
	private Sprite newGameSprite;
	
	// ===========================================================
	// Constructors
	// ===========================================================

	// ===========================================================
	// Getter & Setter
	// ===========================================================

	// ===========================================================
	// Methods for/from SuperClass/Interfaces
	// ===========================================================
	
	@Override
	public Engine onLoadEngine() {
		
		this.camera = new Camera(0, 0, CAMERA_WIDTH, CAMERA_HEIGHT);
        final EngineOptions engineOptions = new EngineOptions(true, ScreenOrientation.PORTRAIT, new RatioResolutionPolicy(CAMERA_WIDTH, CAMERA_HEIGHT), camera);
        engineOptions.getTouchOptions().setRunOnUpdateThread(true);
        return new Engine(engineOptions);
	}

	@Override
	public void onLoadResources() {
		//Sprites
		this.spriteBox = new BitmapTextureAtlas(512,1024);
		this.backgroundTexture = BitmapTextureAtlasTextureRegionFactory.createFromAsset(spriteBox, this, "MenuBackground.png", 0, 0);
		this.newGame = BitmapTextureAtlasTextureRegionFactory.createFromAsset(spriteBox, this, "NewGame.png", 0, 722);
		this.mEngine.getTextureManager().loadTexture(this.spriteBox);
		//Fonts
		this.fontBox = new BitmapTextureAtlas(512,512);
		this.font = FontFactory.createFromAsset(this.fontBox, this, "Zipper blues Black.ttf", 50, true, Color.WHITE);
		this.mEngine.getTextureManager().loadTexture(this.fontBox);
    	this.mEngine.getFontManager().loadFont(this.font);
    	
		//Other
	}

	@Override
	public Scene onLoadScene() {
		this.scene = new Scene(1);
		
		//Background
		this.background = new Sprite(0, 0, backgroundTexture);
		this.scene.getFirstChild().attachChild(background);
		
		//Texts
		this.newGameSprite = new Sprite(100, 500, newGame){
			@Override
        	public boolean onAreaTouched(TouchEvent event,float x, float y){
        		switch(event.getAction()){
        		case TouchEvent.ACTION_DOWN:
        			Intent i = new Intent(MainMenu.this, CrowActivity.class);
                    startActivity(i);
        			break;
        		}
        		return true;
        	}
		};
		this.scene.getFirstChild().attachChild(newGameSprite);
        //this.loadGame = new Text(100, 400, font,"Load Game");
        //this.scene.getFirstChild().attachChild(loadGame);
        
        scene.registerTouchArea(newGameSprite);
        
		return scene;
	}

	@Override
	public void onLoadComplete() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public boolean onSceneTouchEvent(Scene pScene, TouchEvent pSceneTouchEvent) {
		// TODO Auto-generated method stub
		return false;
	}
	// ===========================================================
	// Methods
	// ===========================================================

	// ===========================================================
	// Inner and Anonymous Classes
	// ===========================================================
}
